//
//  HZL_ButtonView.m
//  B_Project
//
//  Created by dllo on 15/11/27.
//  Copyright © 2015年 HZL. All rights reserved.
//

#import "HZL_ButtonView.h"

@implementation HZL_ButtonView

// 重写父类的初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatSubviews];
    }
    return self;
}
// 创建视图
- (void)creatSubviews
{
    self.title = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 60, 15)];
//    self.title.backgroundColor = [UIColor orangeColor];
    self.title.textColor = [UIColor whiteColor];
    self.title.font = [UIFont boldSystemFontOfSize:15];
    [self addSubview:self.title];
    
    self.subTitle = [[UILabel alloc] initWithFrame:CGRectMake(10, 30, self.frame.size.width - 20, 10)];
//    self.subTitle.backgroundColor = [UIColor redColor];
    self.subTitle.textColor = [UIColor whiteColor];
    self.subTitle.font = [UIFont fontWithName:@"GillSans-SemiBoldItalic" size:12];
    [self addSubview:self.subTitle];
    
    self.img = [[UIImageView alloc] initWithFrame:CGRectMake(150, 10.5, 24, 24)];
//    self.img.backgroundColor = [UIColor blackColor];
    [self addSubview:self.img];
}

// 3.自定义响应方法
// 类似于button的事件响应方法
// 传递调用方法的对象 和 调用的方法
- (void)doTarget:(id)target action:(SEL)action
{
    // 把传入的参数赋值给属性
    self.target = target;
    self.action = action;
}
// 4.触发响应的 标识方法
// 类似于button的响应事件 touchUpInside
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// 5.让目标(self.target)调用方法(self.action)
    // 让目标(self.target) 通过对象自己(参数2:self) 调用方法(参数1:self.action)
    [self.target performSelector:self.action withObject:self];
    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
